package com.java.base.thread;

public class TestOrderAfresh {
    static int a, b, x, y, i = 0;

    public static void main(String[] args) throws InterruptedException {

        while (true){
            a = 0;
            b = 0;
            x = 0;
            y = 0;
            i++;
            Thread t1 = new Thread(() -> {
                a = 1;
                x = b;
            });
            Thread t2 = new Thread(() -> {
                b = 1;
                y = a;
            });
            t1.start();
            t2.start();
            t1.join();
            t2.join();

            System.out.println(i + " x=" + x + " y=" + y);
            if (x == 0 && y == 0) {
                System.err.println(i + " x=" + x + " y=" + y);
                break;
            }
        }


    }


    static void sleep(int i) {
        try {
            Thread.sleep(i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
